<?php

use yii\db\Migration;

class m170512_025917_alter_comment extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%comment}}', 'valuator_id', $this->smallInteger() . ' default 0 comment \'评价者id\'');
            $this->addColumn('{{%comment}}', 'valuator_type', $this->string(20) . ' default null comment \'评价者类型（2 学生或家长 1 管理员)）\'');
            $this->addColumn('{{%comment}}', 'accepter_id', $this->smallInteger() . ' default 0 comment \'被评价者id\'');
            $this->addColumn('{{%comment}}', 'accepter_type', $this->string(20) . ' default null comment \'被评价者类型（2 学生或家长 1 管理员)）\'');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%comment}}', 'customer_id');
            $this->dropColumn('{{%comment}}', 'teacher_id');
            $this->dropColumn('{{%comment}}', 'object_type');
            $this->dropColumn('{{%comment}}', 'object_id');
        }
    }
}
